<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    template="/layout/template.xhtml">

<ui:define name="body">

    <h:form id="categoriaSearch" styleClass="edit">

        <rich:simpleTogglePanel label="Categoria: Filtro de Pesquisa" switchType="ajax">

            <s:div styleClass="tableControl" rendered="#{empty from}">
        		<s:link view="/resources/CategoriaEdit.xhtml"
		                    id="create"
		           propagation="none">
		            <h:graphicImage url="/img/add.png"/>
		            #{' '}
		            <h:outputLabel value="Novo"/>
		            
		            <f:param name="grupoId"/>
		            <f:param name="usuarioId" value="#{categoriaList.usuario.id}"/>
		        </s:link>
		    </s:div>
            
            <s:decorate template="/layout/display.xhtml">
                <ui:define name="label">Nome</ui:define>
                <h:inputText id="nome" value="#{categoriaList.categoria.nome}"/>
            </s:decorate>
            
            <s:decorate template="/layout/display.xhtml">
                <ui:define name="label">Descrição</ui:define>
                <h:inputText id="descricao" value="#{categoriaList.categoria.descricao}"/>
            </s:decorate>

            <s:decorate template="/layout/display.xhtml">
                <ui:define name="label">Combinar campos?</ui:define>
                <h:selectOneRadio id="logic" value="#{categoriaList.restrictionLogicOperator}" styleClass="radio">
                    <f:selectItem itemLabel="Sim" itemValue="and"/>
                    <f:selectItem itemLabel="Não" itemValue="or"/>
                </h:selectOneRadio>
            </s:decorate>
			
			<s:decorate template="/layout/display.xhtml">
				<h:commandButton id="search" value="Pesquisar" action="/resources/CategoriaList.xhtml"/>
            	<s:button id="reset" value="Limpar" includePageParams="false"/>
			</s:decorate>
        </rich:simpleTogglePanel>

    </h:form>

	<br clear="left"/>

    <rich:panel>
        <f:facet name="header">Categoria: Resultados da Pesquisa (#{empty categoriaList.resultList ? 0 : (categoriaList.paginated ? categoriaList.resultCount : categoriaList.resultList.size)})</f:facet>
    <div class="results" id="categoriaList">

    <h:outputText value="A pesquisa não retornou resultados."
               rendered="#{empty categoriaList.resultList}"/>

    <rich:dataTable id="categoriaList"
                var="_categoria"
              value="#{categoriaList.resultList}"
           rendered="#{not empty categoriaList.resultList}"
         rowClasses="odd,even"
         	   rows="20">
        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{categoriaList}"/>
                    <ui:param name="propertyLabel" value="Nome"/>
                    <ui:param name="propertyPath" value="categoria.nome"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{_categoria.nome}"/>
        </h:column>
        
        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{categoriaList}"/>
                    <ui:param name="propertyLabel" value="Descrição"/>
                    <ui:param name="propertyPath" value="categoria.descricao"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{_categoria.descricao}"/>
        </h:column>
        
        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{categoriaList}"/>
                    <ui:param name="propertyLabel" value="Usuário"/>
                    <ui:param name="propertyPath" value="categoria.usuario.nome"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{_categoria.usuario.nome}"/>
        </h:column>
        <rich:column styleClass="action">
            <f:facet name="header">Opções</f:facet>
            <s:link view="/resources/#{empty from ? 'Categoria' : from}.xhtml"
                   value="Ver"
             propagation="none"
                      id="categoriaViewId"
                      rendered="#{empty from}">
                <f:param name="categoriaId"
                        value="#{_categoria.id}"/>
                <f:param name="pessoaId"
                        value="#{_categoria.usuario.id}"/>
            </s:link>
            <s:link view="/resources/#{empty from ? 'Categoria' : from}.xhtml"
                   value="Selecionar"
             propagation="default"
                      id="categoriaSelectId"
                      rendered="#{(s:hasRole('Subgrupo') or usuario.id eq _categoria.usuario.id) and not empty from}">
                <f:param name="categoriaId"
                        value="#{_categoria.id}"/>
                <f:param name="pessoaId"
                        value="#{_categoria.usuario.id}"/>
            </s:link>
            #{' '}
            <s:link view="/resources/CategoriaEdit.xhtml"
                   value="Editar"
             propagation="none"
                      id="categoriaEdit"
                rendered="#{(s:hasRole('Subgrupo') or usuario.id eq _categoria.usuario.id) and empty from}">
                <f:param name="categoriaId"
                        value="#{_categoria.id}"/>
            </s:link>
        </rich:column>
    </rich:dataTable>

    </div>
    </rich:panel>

    <div class="tableControl">

        <s:link view="/resources/CategoriaList.xhtml"
            rendered="#{categoriaList.previousExists}"
               value="#{messages.left}#{messages.left} #{messages.firstPage}"
                  id="firstPage">
          <f:param name="firstResult" value="0"/>
        </s:link>

        <s:link view="/resources/ategoriaList.xhtml"
            rendered="#{categoriaList.previousExists}"
               value="#{messages.left} #{messages.previousPage}"
                  id="previousPage">
            <f:param name="firstResult"
                    value="#{categoriaList.previousFirstResult}"/>
        </s:link>

        <s:link view="/resources/CategoriaList.xhtml"
            rendered="#{categoriaList.nextExists}"
               value="#{messages.nextPage} #{messages.right}"
                  id="nextPage">
            <f:param name="firstResult"
                    value="#{categoriaList.nextFirstResult}"/>
        </s:link>

        <s:link view="/resources/CategoriaList.xhtml"
            rendered="#{categoriaList.nextExists}"
               value="#{messages.lastPage} #{messages.right}#{messages.right}"
                  id="lastPage">
            <f:param name="firstResult"
                    value="#{categoriaList.lastFirstResult}"/>
        </s:link>

    </div>

</ui:define>

</ui:composition>
